package com.migu.utils

import java.text.SimpleDateFormat
import java.util.{Calendar, Date}

/**
 * Created by maguoyun on 2017/03/22.
 */
object DateUtil {
  val sfIn = new SimpleDateFormat("yyyyMMddHHmmss")
  val sfOut = new SimpleDateFormat("yyyyMMdd_HH_mm")

  val pvSfOut = new SimpleDateFormat("yyyyMMdd_HH_")
  val wangduSfOut = new SimpleDateFormat("yyyyMMddHH_")
  val filterJspSfOut = new SimpleDateFormat("yyyyMMdd")

  val formatDate = new SimpleDateFormat("yyyyMMddhhmmss")

  def getOnlineUserDateStr(): String = {
    val date = new Date()
    pvSfOut.format(date) + getMinStr(date)
  }

  def getFilterJspDateStr(): String = {
    val date = new Date()
    filterJspSfOut.format(date)
  }

  def getWangduPvDateStr(): String = {
    val date = new Date()
    wangduSfOut.format(date) + getMinStr(date)
  }

  def getMinStr(date: Date): String = {
    val min = date.getMinutes / 5 * 5
    min match {
      case 0 => "00"
      case 5 => "05"
      case _ => min.toString
    }
  }

  def getDayStr():String = {
    val date = new Date()
    filterJspSfOut.format(date)
  }

  def getDate(date: String): Date = {
    formatDate.parse(date)
  }

  def addDay(curTimestamp: Long, day: Int): String = {
    val curDate = formatDate.format(curTimestamp)
    val beginDate = formatDate.parse(curDate)
    val date = Calendar.getInstance()
    date.setTime(beginDate)
    date.set(Calendar.DATE, date.get(Calendar.DATE) + day)
    //formatDate.parse(formatDate.format(date.getTime()))
    date.getTime.getTime.toString
  }

  def main(args: Array[String]): Unit = {

  }
}
